From: Colin Walters Date: Fri, 30 Jun 2017 01:45:26 +0000 (-0400) Subject: lib/commit: Fix a tmpfile fd leak in static delta processing X-Git-Tag: archive/raspbian/2022.1-3+rpi1~1^2~4^2~35^2~8 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/success//%22http:/www.example.com/cgi/success/?a=commitdiff_plain;h=192e7b888f8cfcf4f02b0b5b6b502e679e91a4a1;p=ostree.git lib/commit: Fix a tmpfile fd leak in static delta processing I had thought `glnx_link_tmpfile_at()` actually consumed the tmpfile; it does consume the *path* but not the fd. In the non-delta path things were fine since we used the autocleanup. But the delta code had a tmpfile allocated in its struct that got reused, and hence leaked the fd. Fix this by making the commit API actually consume the tmpfile fully, just like the path path. Closes: #986 Approved by: jlebon --- diff --git a/src/libostree/ostree-repo-commit.c b/src/libostree/ostree-repo-commit.c index ae3760c0..bc55fd6f 100644 --- a/src/libostree/ostree-repo-commit.c +++ b/src/libostree/ostree-repo-commit.c @@ -156,8 +156,12 @@ _ostree_repo_commit_tmpf_final (OstreeRepo *self, cancellable, error)) return FALSE; - return glnx_link_tmpfile_at (tmpf, GLNX_LINK_TMPFILE_NOREPLACE_IGNORE_EXIST, - dest_dfd, tmpbuf, error); + if (!glnx_link_tmpfile_at (tmpf, GLNX_LINK_TMPFILE_NOREPLACE_IGNORE_EXIST, + dest_dfd, tmpbuf, error)) + return FALSE; + /* We're done with the fd */ + glnx_tmpfile_clear (tmpf); + return TRUE; } /* Given a dfd+path combination (may be regular file or symlink),